package com.example.Util;

import org.junit.jupiter.api.Test;

import java.text.SimpleDateFormat;
import java.util.*;

public class Tools {

    /**
     * 参数A-Z排序
     *
     * @param mapData map 数据
     * @return String
     */
    public static String mapDataSortAToZ(Map<String, String> mapData) {
        List<Map.Entry<String, String>> list = new ArrayList<>(mapData.entrySet());
        //升序排序
        list.sort(Comparator.comparing(Map.Entry::getKey));
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> mapping : list) {
            if (mapping.getValue() == null || "".equals(mapping.getValue())) {
                continue;
            }
            if (sb.length() > 0) {
                sb.append("&");
            }
            sb.append(mapping.getKey());
            sb.append("=");
            sb.append(mapping.getValue());

        }
        return sb.toString();
    }

    @Test
    public void testMethod2(){

        String str = "{\"version\":\"1.0\",\"encoding\":\"utf-8\",\"ret_code\":\"0000\",\"ret_msg\":\"查询成功\",\"agent_id\":\"1664502\",\"SumRealAmt\":\"0.0100\",\"SumSettleAmt\":\"0.0098\"," +
                "\"SumBillAmt\":\"1\",\"SumFeeAmt\":\"0.0002\",\"ComRealAmt\":\"0.0100\",\"ComSettleAmt\":\"0.0098\",\"ComBillCount\":\"1\",\"GuaranteeSettleAmt\":\"0.0000\"," +
                "\"GuaranteeBillCount\":\"0\",\"RefundAmt\":\"0.0000\",\"RefundBillCount\":\"0\",\"RefundAccountAmt\":\"0.0000\",\"RefundLoanAmt\":\"0.0000\"," +
                "\"IsOutFee\":\"False\",\"sign\":\"b69637e6af92e33070702165b8287c0f\"}";

        Map<String, String> tmap = new HashMap<>();
        tmap.put("version", "1.0");
        tmap.put("encoding", "utf-8");
        tmap.put("ret_code", "0000");
        tmap.put("ret_msg", "查询成功");
        tmap.put("agent_id", "1664502");
        tmap.put("sumrealamt", "0.0100");
        tmap.put("sumsettleamt", "0.0098");
        tmap.put("sumbillamt", "1");
        tmap.put("sumfeeamt", "0.0002");
        tmap.put("comrealamt", "0.0100");
        tmap.put("comsettleamt", "0.0098");
        tmap.put("combillcount", "1");
        tmap.put("guaranteesettleamt", "0.0000");
        tmap.put("guaranteebillcount", "0");
        tmap.put("refundamt", "0.0000");
        tmap.put("refundbillcount", "0");
        tmap.put("refundaccountamt", "0.0000");
        tmap.put("refundloanamt", "0.0000");
        tmap.put("isoutfee", "false");
        tmap.put("key", "1c3a345d4f1e48b7a02b90ac");



        String a = mapDataSortAToZ(tmap);
        System.out.println(a);
    }



    /**
     * 获取当前14位时间戳
     * @return String
     */

    public static String GetTimeStamp14Time (){
        // 获取当前14位时间戳
        Date now = new Date();
        // 创建 SimpleDateFormat 对象，指定日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        return dateFormat.format(now);
    }

}
